<!--
 * @Description: 
 * @Author:  huangshuai
 * @Date: 2023-10-16 16:29:27
 * @LastEditTime: 2023-10-22 11:06:44
 * @LastEditors: huangshuai 
-->
<template>
  <div class="report-handle" v-loading="loading">
    <el-table :data="tableData" stripe style="width: 95%" border>
      <el-table-column
        prop="content"
        label="内容"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="分类" width="180">
        <template #default="scope">
          <span v-if="scope.row.reportCategory === '0'"> 宠物方面</span>

          <span v-else-if="scope.row.reportCategory === '1'">住户方面</span>
          <span v-else-if="scope.row.reportCategory === '2'"
            >社区管理人方面</span
          >
          <span v-else-if="scope.row.reportCategory === '3'">其他方面</span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="createTime" label="创建时间" />
      <el-table-column align="center" prop="updateTime" label="审核时间" />
      <el-table-column align="center" label="审核状态">
        <template #default="scope">
          <el-button
            v-if="scope.row.examineStatus === 0"
            size="small"
            type="info"
            @click="handleUnaudited(scope.row.id)"
            >正在审核</el-button
          >
          <el-button
            v-else-if="scope.row.examineStatus === 1"
            size="small"
            type="primary"
            >审核未通过</el-button
          >
          <el-button
            v-else-if="scope.row.examineStatus === 2"
            size="small"
            type="success"
            >审核通过</el-button
          >
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleCheck(scope.row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div style="width: 95%; margin-top: 10px">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 15, 20, 25]"
        :small="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>

  <!-- 未审核状态-====》》》审核不通过 | 审核通过-----弹框 -->
  <el-dialog v-model="statusDialog" title="切换审核状态" width="30%">
    <div class="dialog-context">
      <el-button
        size="large"
        type="info"
        class="dialog-button"
        :class="{ selectedButton1: isSelectedStatus === 1 }"
        @click="isSelectedStatus = 1"
        >审核不通过</el-button
      >
      <el-button
        size="large"
        type="info"
        class="dialog-button"
        :class="{ selectedButton2: isSelectedStatus === 2 }"
        @click="isSelectedStatus = 2"
        >审核通过</el-button
      >
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="(statusDialog = false), (isSelectedStatus = -1)"
          >取消</el-button
        >
        <el-button type="primary" @click="confirmChange(isSelectedStatus)">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>

  <ContentDialog ref="contentDialogRef" />
</template>

<script setup lang="ts">
import { ref, onMounted, reactive } from "vue";
import ContentDialog from "./content-dialog.vue";
import { ElMessage } from "element-plus";
import {
  listApplyCancelBadRecordInfo,
  updateBadRecordStatus,
} from "@/api/manager";

//记录请求发送的id  &&  status
const userInfo = reactive<{ reportId: number; status: number }>({
  reportId: -1,
  status: -1,
});

const tableData = ref<any>([]);
//-------------------------
//分页
//-------------------------
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const handleSizeChange = () => {
  getListData();
};
const handleCurrentChange = () => {
  getListData();
};
//-------------------------
//---------弹框-----------
//-------------------------
const contentDialogRef = ref(); //查看用户理由   》》》   弹框
const handleCheck = (data: any) => {
  contentDialogRef.value.showDialog(data);
};
const isSelectedStatus = ref<number>(-1); //按钮选择

//***************
//点击未审核状态---------弹框
//***************
const statusDialog = ref(false); //切换正在审核和审核完成状态
const handleUnaudited = (id: number) => {
  //未审核 ====>>>  审核不通过  |  审核通过
  isSelectedStatus.value = -1;
  userInfo.reportId = id;
  statusDialog.value = true;
};

const confirmChange = async (statusData: number) => {
  statusDialog.value = false;
  await updateBadRecordStatus(userInfo.reportId, statusData).then(
    (res: any) => {
      ElMessage({
        message: res.message,
        type: "success",
      });
      getListData();
      isSelectedStatus.value = -1;
    }
  );
};
const loading = ref<boolean>(false);
//*************************
//******获取列表信息*********
//*************************
const getListData = async () => {
  loading.value = true;
  await listApplyCancelBadRecordInfo(currentPage.value, pageSize.value).then(
    (res: any) => {
      tableData.value = res.data;
      total.value = +res.total;
    }
  );
  loading.value = false;
};

onMounted(() => {
  getListData();
});
</script>

<style scoped lang="less">
.report-handle {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  padding-top: 10px;
  :deep(.el-popper) {
    display: none;
  }
}
.selectedButton2 {
  background-color: #67c23a;
}
.selectedButton1 {
  background-color: #409eff;
}
.dialog-context {
  width: 100%;
  // background-color: red;
  display: flex;
  justify-content: center;
}
.dialog-button {
  width: 120px;
  height: 50px;
  margin: 20px;
}
</style>
